<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
		<!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
		<meta name="renderer" content="webkit">
		<meta name="keywords" content="搜索关键字，以半角英文逗号隔开" />
		<title>冷链物流管理系统</title>

		<!-- 公共样式 开始 -->
		<link rel="shortcut icon" href="images/favicon.ico"/>
		<link rel="bookmark" href="images/favicon.ico"/>
		<link rel="stylesheet" type="text/css" href="css/base.css">
		<link rel="stylesheet" type="text/css" href="css/iconfont.css">
		<script type="text/javascript" src="framework/jquery-1.11.3.min.js" ></script>
		<link rel="stylesheet" type="text/css" href="layui/css/layui.css">
	    <!--[if lt IE 9]>
	      	<script src="framework/html5shiv.min.js"></script>
	      	<script src="framework/respond.min.js"></script>
	    <![endif]-->
		<script type="text/javascript" src="layui/layui.js"></script>
		<!-- 滚动条插件 -->
		<link rel="stylesheet" type="text/css" href="css/jquery.mCustomScrollbar.css">
		<script src="framework/jquery-ui-1.10.4.min.js"></script>
		<script src="framework/jquery.mousewheel.min.js"></script>
		<script src="framework/jquery.mCustomScrollbar.min.js"></script>
		<script src="framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
		<!-- 公共样式 结束 -->

		<link rel="stylesheet" type="text/css" href="css/login.css">
		<script type="text/javascript" src="js/login.js"></script>
		<script language="javascript" type="text/javascript">
		     
			var code;
			function createCode() {  //函数体
				code = "";
				var codeLength = 5; //验证码的长度
				var checkCode = document.getElementById("checkCode");
				var codeChars = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
				'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
				'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //所有候选组成验证码的字符，当然也可以用中文的
				for (var i = 0; i < codeLength; i++)
				{
					var charNum = Math.floor(Math.random() * 52);//设置随机产生
					code += codeChars[charNum];
				}
				if (checkCode)
				{
					checkCode.className = "code";
					checkCode.innerHTML = code;
				}
			}        
		</script>
	</head>

	<style>
	    /*验证码*/
	.code
	    {
	          background-color: silver;
	            font-family:Arial; /*设置字体*/
	            font-style:initial;
	             color:brown;
	             font-size:20px;
	             border:0;
	              padding:2px 3px;
	             letter-spacing:3px;
	             font-weight:bolder;            
	              
	             width:81px;
	             height:23px;      
	             margin-left: 120px;
	             margin-top: -35px;
	 
	    }
	    a
	    {
	        text-decoration:none;
	        font-size:12px;
	        color:#288bc4;
	        }
	    a:hover
	    {
	       text-decoration:underline;
	        }
	       .yz{
	         position: absolute;
	          margin-left: 220px;
	          margin-top:-10px;
	        }
	         
	</style>

	<body onload="createCode()">
		
		<!--主体 开始-->
		<div class="login_main">
			<!--轮播图 开始-->
			<div class="layui-carousel lbt" id="loginLbt">
				<div carousel-item>
					<div class="item" style="background: url(images/login_bg1.jpg) no-repeat; background-size: cover;"></div>
					<div class="item" style="background: url(images/login_bg2.jpg) no-repeat; background-size: cover;"></div>
				</div>
			</div>
			<!--轮播图 结束-->
			<div class="logo" style="margin-left: 35px;">
				<div>
					<h1>冷链物流管理系统	</h1>
					<p>版本号:110.9527</p>
				</div>
			</div>
			<div class="form_tzgg" style="margin-left:50px;margin-top:60px;">
				<div class="form">
					<form action="" method="post" class="layui-form">
						<br/><div class="title">用户登录</div>
						<div class="con" onclick="getFocus(this)">
							<input type="text" id="userid" name="userid" lay-verify="userName" placeholder="请输入您的用户名" autocomplete="off" class="layui-input">
						</div><br/>
						<div class="con" onclick="getFocus(this)">
							<input type="password" id="pwd" name="pwd" required  lay-verify="passWord" placeholder="请输入您的账户密码" autocomplete="off" class="layui-input">
						</div><br/>
						<div class="com">
							<input placeholder="请输入验证码" id="YZ" name="yz" width="30px;">
						</div><br/>
						<div class="code" id="checkCode" onclick="createCode()" style="margin-left:240px;margin-top:-70px;"></div><br/><br/>
						
						<div class="but">
						<button type="button" id="btnLogin">登录</button>
						</div>
						<div class="apply"><a href="register.html"><h2>注册申请</h2></a></div>
					</form>
				</div>
			</div>
		</div>
		<!--主体 结束-->
	</body>
	<script src="layui/layui.all.js"></script>
	<script type="text/javascript" src="js/md5.js"></script>
	<script type="text/javascript" src="js/systempublickey.js"></script>
	<script src="js/application.js"></script>
	<script>
		layui.use([ 'table', 'form', 'layer',  'laytpl', 'element','laydate' ], function() {
			var table = layui.table, form = layui.form, 
				layer = layui.layer, $ = layui.jquery,
				element = layui.element,laydate = layui.laydate;
				
			//登录开始
			$("#btnLogin").click(function(){
				var userid = $("#userid").val();
				var pwd = $("#pwd").val();
				var yz = $("#YZ").val();
				var YZ = yz.toUpperCase();
				var YZs = code.toUpperCase();
				
				/* 用MD5将密码做加密处理 */
				var enpwd = hex_md5(fix(userid,pwd));
				$("#pwd").val(enpwd);
				var param = '?userid='+userid+'&pwd='+enpwd;//参数组合
				//alert(param);
				
				if(userid==null || userid=="" || userid==undefined){
					$("#userid").focus("");
					return;
				}else if(pwd==null || pwd=="" || pwd==undefined){
					$("#pwd").focus();
					return;
				}else if(pwd.length<6 || pwd.length>18){
					layer.alert('密码长度不符合规范!', {icon: 2});
					return;
				}else if(YZ==""){
					alert("验证码不能为空！");
			        createCode();//输错一次或提交一次都将会刷新一次验证码
			        return; //结束本次会话
				}else if(YZ!=code.toUpperCase()){
					alert("您输入的验证码有误，请重新输入！！");
			        createCode();//读取文件
			        return; //结束本次会话
				}
				$.ajax({
					url : urlapi+'user/userlogin'+param,
					type : 'get',
					 xhrFields: {
					  withCredentials: true
					 },
					 crossDomain: true,
					success : function(data) {
						console.log(data);
						if(data.code == 0){
							location.href = "frame.html";
						}else if(data.code == 1) {
							layer.alert('账号或密码错误!', {
								icon: 2
							});
							$("#userid").focus();
							$("#userid").val("");
							$("#pwd").val("");
						}else{
							
						}
					},
					error: function (XMLHttpRequest, textStatus) { //请求失败error.html
						location.href = "error.html";
						/* alert("500,服务器内部错误"); */
					}
				});
			})
		})
	</script>
</html>